<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>数据处理</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet" href="css/common.css" type="text/css" />
		<link rel="stylesheet" href="css/jquery-ui-1.8.5.custom.css"
			type="text/css" />
		<style>
.my-dialog .ui-dialog-titlebar-close {
	display: none;
}
</style>
		<script src="<%=basePath%>js/jquery-1.5.js" language="javascript">
</script>
		<script src="<%=basePath%>js/jquery-ui-1.8.5.custom.min.js"
			language="javascript">
</script>

		<script type="text/javascript">
		
	
$(function(){
		
			var isSpecialUser=${sessionScope.isSpecialUser};//特殊帐号，屏蔽增删改的功能
			
			//$("a[id^='changeState'],a[id^='deleteDorm']").attr("href",'javascript:alert("jj")');
			
			if(isSpecialUser){
				window.doOneKeyAssignDorm=window.backUpDB=function(){
					alert("Sorry!!该帐号权限不够，不能进行此操作")
				}
			}
})
$(function() {
	$("input[type='button']").button();
	var collegesList = '<s:property value="collegesJson" escape="false"/>';
	collegesList = eval('(' + collegesList + ')');
	for ( var i = 0; i < collegesList.length; i++) {
		$("#colleges").append(
				"	<tr ><td><input type='checkbox' value="
						+ collegesList[i].collegeId
						+ " name='colleges'></td><td>"
						+ collegesList[i].collegesName + "</td>	</tr>");

	}
})

function onekeyAssignDorm() {
	//alert("一键分配宿舍")

	if (!$("#selectColleges").is(":hidden")) {//学院选择div展开时点击分配
		var colleges = $("input[name='colleges']:checked");
		if (colleges.length < 1) {
			alert("请先选择要进行分配的学院")
			return;
		}
		var collegeArray = [];
		colleges.each(function(i, v) {
			collegeArray.push($(this).val())
		})
		doOneKeyAssignDorm(collegeArray);
	}
	$("#selectColleges").slideToggle("slow");
}
//执行一键分配宿舍
function doOneKeyAssignDorm(colleges) {
	if (confirm("本次操作将为本学院所有已缴费但尚未分配宿舍的学生自动分配宿舍，确定执行此操作？？")) {
		$("#onekeyAssignDormDiv").show();
		$("#assignInfo").html("");
		$("#onekeyAssignDormDiv").dialog( {
			modal : true,
			width : 700,
			dialogClass : "my-dialog",
			buttons : {
				'完成' : function() {
					$("#onekeyAssignDormDiv").dialog("close")
					$("#onekeyAssignDormDiv").hide();
				}
			}
		})

		dlBtnEnable(false);
		$("#assignProgress").show();

		$.post("json/onekeyAssignDormAction", {
			'date' : new Date(),
			"collegeArray" : colleges + ""

		}, function(data) {
			dlBtnEnable(true);
			$("#assignInfo").html("执行成功！本次操作成功为" + data.result + "位学生自动分配了宿舍");
			$("#assignProgress").hide();
			$("#showtip2").hide();
		})
	}
}
//控制按钮是否可用的函数.

function dlBtnEnable(enable)

{

	var dlgButton = $('.ui-dialog-buttonpane button');

	if (enable) {

		dlgButton.attr('disabled', '');

		dlgButton.removeClass('ui-state-disabled');

	} else {

		dlgButton.attr('disabled', 'disabled');

		dlgButton.addClass('ui-state-disabled');

	}

}

/*function operateIndex(operate) {
 if (confirm("确定执行此操作？？")) {

 if(operate == "backup"){
 $("input[name=indexs][@value=backup]").attr("checked", false);
 $("#backup_form").attr("action", "backupAndDownloadZip").submit();
 } else {

 $("input[name=indexs][@value=backup]").attr("checked",false);
 $("#backup_form").attr("action","backupAndDownloadZip").submit();
 if(operate == "check"){
 $("#lockDirTable").hide();
 $("#operateIndexDiv").show();
 $("#indexsInfo").html("");
 $("#importErrorTable").hide();
 $("#operateIndexDiv").dialog( {
 modal : true,
 width : 700,
 height : 500,
 dialogClass : "my-dialog",
 buttons : {
 '完成' : function() {
 $("#operateIndexDiv").dialog("close")
 $("#operateIndexDiv").hide();
 }
 }
 })

 dlBtnEnable(false);
 $("#assignProgress").show();
 $.post("json/adminOperateIndex", {
 'date' : new Date(),
 "oprator" : operate

 }, function(data) {

 var result=eval("("+data.result+")");
 if(result.size <= 0){
 var table=$("#importErrorTable")
 $("#indexsInfo").html("执行成功！");
 $("#assignProgress").hide();

 $("table#importErrorTable tr:gt(0)").remove();
 var i = 0;
 for(d in result){
 var tr='<tr><td align="center">'+(i+1)+'</td><td align="left" ><font color="red">'+ d +'</font></td><td align="center">' + result[d] + '</td></tr>';
 var i = i + 1;
 table.append($(tr));
 }
 $("table#importErrorTable tr:gt(0):even").css('background','#deefff'); 
 $("table#importErrorTable tr:gt(0):odd").css('background','#fff');
 $("#checkingImage").attr("src","images/error.png")
 $("#importErrorTable").show();
 }else{
 $("#indexsInfo").html("索引库里没有出现重复的索引值");
 }

 $("#operateIndextable").hide();
 $("#checkingImage").show();
 $("#checkingProgress").hide();
 $("#importErrorDiv").show();
 dlBtnEnable(true);



 })
 }else{

 $("#operateIndexDiv").show();
 $("#indexsInfo").html("");

 $("#indexProgress").show();

 $("#importErrorTable").hide();

 $("#operateIndexDiv").dialog( {
 modal : true,
 width : 700,
 height : 500,
 dialogClass : "my-dialog",
 buttons : {
 '完成' : function() {
 $("#operateIndexDiv").dialog("close")
 $("#operateIndexDiv").hide();
 }
 }
 })

 dlBtnEnable(false);
 $("#assignProgress").show();
 $.post("json/adminOperateIndex", {
 'date' : new Date(),
 "oprator" : operate

 }, function(data) {
 var result=eval("("+data.result+")");   
 var table=$("#lockDirTable")
 $("table#lockDirTable tr:gt(0)").remove();

 if(result.length > 0){
 $("#indexsInfo").html("执行成功！");
 $("#assignProgress").hide();
 for(var i = 0 ;i < result.length ;i++){
 var info = '<tr><td>' + (i+1) +'</td><td><font color ="red" >' + result[i] + '</font></td></tr>';
 table.append(info);
 }
 }else{
 $("#lockDirTable").hide();
 $("#indexsInfo").html("执行成功！未发现文件锁");
 }

 $("table#lockDirTable tr:gt(0):even").css('background','#deefff'); 
 $("table#lockDirTable tr:gt(0):odd").css('background','#fff');
 $("#operateIndextable").hide();
 $("#checkingImage").show();
 $("#checkingProgress").hide();
 $("#importErrorDiv").show();
 dlBtnEnable(true);

 $("#indexsInfo").html("执行成功！");
 $("#indexProgress").hide();

 })
 }
 }
 }*/
function dealIndex() {
	if (!$("#selectIndex").is(":hidden")) {
		if ($("input:[name=indexs]:radio:checked").length == 0) {
			alert("请先选择操作")
			return;
		}
		operateIndex($("input:[name=indexs]:radio:checked").val())
		//doOneKeyAssignDorm(collegeArray);
	}
	$("#selectIndex").slideToggle("slow");
}

function closeCollegeChoose() {

	$("#selectColleges").slideToggle("slow");
}

function closeIndexChoose() {

	$("#selectIndex").slideToggle("slow");
}

function closeDatabaseChoose() {
	$("#operateDataBase").slideToggle("slow");
}
function backUpDB() {
	if (!$("#operateDataBase").is(":hidden")) {
		var operate = $("input[name='dataBase']:checked").val();
		var opString = operate == 'backup' ? "备份" : "还原";
		if(operate!="backup"){
			alert("本系统暂不支持还原!")
			return;
		}
		if (confirm("确定" + opString + "数据库")) {
			$("#backupDataBaseDiv").show();
			$("#operation").html(opString);
			$("#backupInfo").html("");
			$("#backupProgress").show();
			$("#backupDataBaseDiv").dialog( {
				modal : true,
				width : 700,
				dialogClass : "my-dialog",
				buttons : {
					'完成' : function() {
						$("#backupDataBaseDiv").dialog("close")
						$("#backupDataBaseDiv").hide();
						$("#showtip").hide();
					}
				}
			})

			dlBtnEnable(false);
			$("#backupProgress").show();

			$.post("json/backupOrRestoreDBAction", {
				'date' : new Date(),
				"dbOperation" : operate
			}, function(data) {
				dlBtnEnable(true);
				$("#backupInfo").html("执行成功！");
				$("#backupProgress").hide();
				$("#showtip").hide();
			})
		}

	}
	$("#operateDataBase").slideToggle("slow");

}
</script>
	</head>

	<body>
		<div class="adminhead">
			<jsp:include page="head.jsp"></jsp:include>
		</div>
		<div class="adminmain">
			<div class="left">
				<jsp:include page="leftMenu.jsp"></jsp:include>
			</div>
			<div class="right">

				<div id="nav">
					<ul>
						<li class="bg_image_onclick">
							数据处理
						</li>
					</ul>
				</div>
				<div id="sub_info">
					&nbsp;&nbsp;
					
					&nbsp;
					<span id="show_text">欢迎进入新生报告系统后台管理!</span>您现在正在：管理员操作&gt;&gt;&gt;数据处理
				</div>

				<div id="man_zone">
										
				<div style="margin-top: 100px">
					<table border="0" align="center" width="80%">
						<tr style="height: 210px">
							<td>
								<div id="operateDataBase" style="display: none">

									<table
										style="border-color: #00eeff; font-size: 12px; border-style: double; border-width: 1; width: 180px">
										<tr>
											<td colspan="2" style="font-weight: bold; font-size: 14px">
												请选择要执行的操作
												<img src="images/close.png"
													style="float: right; cursor: pointer;"
													onclick="closeDatabaseChoose()">
											</td>

										</tr>

										<tr>
											<td>
												<input type="radio" name="dataBase" value="backup"
													checked="checked">
												备份
											</td>
										</tr>
										<tr>
											<td>
												<input type="radio" name="dataBase" value="restore">
												还原
											</td>
										</tr>

									</table>
								</div>
							</td>

							<!--<td>
								<div id="selectIndex" style="display: none">
									<form action="" id="backup_form">
										<table
											style="border-color: #00eeff; font-size: 12px; border-style: double; border-width: 1; width: 180px"
											id="index">
											<tr>
												<td colspan="2" style="font-weight: bold; font-size: 14px">
													请选择操作
													<img src="images/close.png"
														style="float: right; cursor: pointer;"
														onclick="closeIndexChoose()">
												</td>
											</tr>
											<tr>

												<td>
													<form action="" id="backup_form">
														<input type="radio" name="indexs" value="backup">
														备份索引库
														<br />
													</form>

													<td>
														<input type="radio" name="indexs" value="backup">
														备份索引库
														<br />
														<br />


													</td>
											</tr>
											<tr>
												<td>

													<input type="radio" name="indexs" value="check">
													检测索引库
													<br />
													<br />

													<input type="radio" name="indexs" value="check">
													检测索引库
													<br />
													<br />

												</td>
											</tr>
											<tr>
												<td>

													<input type="radio" name="indexs" value="rebuild">
													重建索引库
													<br />

													<input type="radio" name="indexs" value="delete">
													移除索引锁

												</td>
											</tr>
										</table>
									</form>
								</div>
							</td>
							--><td>
								<div id="selectColleges" style="display: none">

									<table
										style="border-color: #00eeff; font-size: 12px; border-style: double; border-width: 1; width: 180px"
										id="colleges">
										<tr>
											<td colspan="2" style="font-weight: bold; font-size: 14px">
												请选择要分配的学院
												<img src="images/close.png"
													style="float: right; cursor: pointer;"
													onclick="closeCollegeChoose()">
											</td>
										</tr>

									</table>
								</div>
							</td>
						</tr>
						<tr valign="middle">
							<td>
								<input type="button" value="操作数据库" onclick="backUpDB()" />
							</td>
							<!--<td>
								<input type="button" value="操作索引" onclick="dealIndex()" />

							</td>
							--><td>

								<input type="button" value="一键分配宿舍" onclick="onekeyAssignDorm()" />
							</td>
						</tr>
						<tr>
							<td>
								<img alt="" src="images/arrow.png">
							</td>
							<!--<td>
								<img alt="" src="images/arrow.png">
							</td>
							--><td>
								<img alt="" src="images/arrow.png">
							</td>
						</tr>
						<tr valign="top">
							<td>
								<font color="red" size="2">点下此键将进行数据库备份或还原 </font>
							</td>
							<!--<td>
								<font color="red" size="2">点下此键将操作全文检索所生成的索引</font>
							</td>
							--><td>
								<font color="red" size="2">点下此键将自动为全校所有已缴费<br />但尚未分配到宿舍的学生自动分配宿舍</font>
							</td>
						</tr>
					</table>



				</div>
				<div id="onekeyAssignDormDiv" style="display: none" title="正在自动分配宿舍">

					<center>
					<div>
						<p style="font-size: 12px; color: red" id="showtip2">
							正在分配，请稍等。。。
						</p>
						<img src="images/progressBar.gif" alt="" id="assignProgress" />
						<p id="assignInfo" style="font-size: 16px; color: red"></p>
					</center>
				</div>
				<div id="backupDataBaseDiv" style="display: none" title="正在操作数据库">


					<center>
						<p style="font-size: 12px; color: red" id="showtip">
							正在
							<span id="operation">备份</span>，请稍等。。。
						</p>
						<img src="images/progressBar.gif" alt="" id="backupProgress" />
						<p id="backupInfo" style="font-size: 16px; color: red"></p>
					</center>
				</div><!--

				<div id="operateIndexDiv" style="display: none" title="正在操作索引库">

					<center>
						<p style="font-size: 12px; color: red">
							正在操作，请稍等。。。
						</p>
						<img src="images/progressBar.gif" alt="" id="indexProgress" />
						<p id="indexsInfo" style="font-size: 16px; color: red"></p>
					</center>

					<p id="indexsInfo" style="font-size: 16px; color: red"
						align="center"></p>
					<table id="operateIndextable" align="center">
						<tr>
							<td>
								<p style="font-size: 12px; color: red">
									正在操作，请稍等。。。
								</p>
								<img src="images/progressBar.gif" alt="" id="assignProgress" />
							</td>
						</tr>
					</table>

					<table id="lockDirTable" width="100%" border="0" style=""
						class="t1">
						<tr>
							<th>
								序号
							</th>
							<th>
								移除以下路径的锁
							</th>
						</tr>
					</table>

					<table id="importErrorTable" width="100%" border="0" style=""
						class="t1">
						<tr style="font-size: 18px; font-weight: bold; color: red">
							<th width="20%" align="center">
								序号
							</th>
							<th width="45%">
								名称
							</th>
							<th align="center" width="20%">
								索引值
							</th>
					</table>

					</div>
				--></div>
			</div>
		</div>
		<div class="adminfooter">
			<jsp:include page="footer.jsp"></jsp:include>
		</div>

	</body>
</html>
